package worktime.yft.demo.Controller;

import net.minidev.json.JSONArray;
import net.minidev.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import worktime.yft.demo.Annotation.UserLoginToken;
import worktime.yft.demo.Service.UserService;

@RestController
@CrossOrigin
public class UserController {
    @Autowired
    private UserService userservice;

    @RequestMapping("login")
    public JSONObject Login(String username,String password){
        System.out.println();
        return userservice.Login(username,password);
    }

    @UserLoginToken
    @RequestMapping("pswchange")
    public boolean PswChange(String id,String old,String password){
        return userservice.updatePsw(id,old,password);
    }

    //@UserLoginToken
    @RequestMapping("findUserAndDepartment")
    public JSONArray findUserAndProjects(){
        return userservice.findUserAndDepartment();
    }

    @UserLoginToken
    @RequestMapping("findDepartments")
    public JSONObject findDepartments(){
        return userservice.findDepartments();
    }
}
